class Solution {
public:
    int cnt = 0;
    int kthSmallest(TreeNode* root, int k) {
        if (!root)
            return -1;
            
        int lVal = kthSmallest(root->left, k);
        if (lVal >= 0)
            return lVal;
            
        cnt++;
        if (cnt == k)
            return root->val;
            
        int rVal = kthSmallest(root->right, k);
        return rVal;
    }
};